package com.homework;

/**
 * @Author MDD
 * @Description
 * @Version
 * @Date
 **/
public class UseComputeTest {
    public static void main(String[] args) {
        UseCompute test = new UseCompute();
        test.useCom(new jia(),5,6);

        test.useCom(new jian(),8,4);

        test.useCom(new cheng(),2,6);

        test.useCom(new chu(),6,3);

    }

}
class UseCompute{
    public void useCom(ICalculator calc,int one,int two){
        System.out.println(calc.calculate(one,two));
    }
}

interface ICalculator{
    int  calculate(int n,int m);
}

class jia implements ICalculator{

    @Override
    public int calculate(int n, int m) {
        return n + m;
    }
}
class jian implements ICalculator{

    @Override
    public int calculate(int n, int m) {
        return n - m;
    }
}

class cheng implements ICalculator{
    @Override
    public int calculate(int n, int m) {
        return n * m;
    }
}

class chu implements ICalculator{
    @Override
    public int calculate(int n, int m) {
        if (m==0){
            System.out.println("除数不能为零！");
            return 0;
        }
        else {
            return n / m;
        }
    }
}